<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_themeRange"></title>
    <script type="text/javascript" src="../js/include-web.js"></script>
    <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
<div id="map" style="width: 100%;height:100%"></div>
<script type="text/javascript">
    var map, themeLayer, options
    url = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/map-china/rest/maps/China";
    new ol.supermap.MapService(url).getMapInfo().then(function (serviceResult) {
        var mapJSONObj = serviceResult.result;
        map = new ol.Map({
            target: 'map',
            // ol v7版本用法为ol.control.defaults.defaults； v6版本以下用法为ol.control.defaults
            controls: ol.control.defaults.defaults({attributionOptions: {collapsed: false}})
                .extend([new ol.supermap.control.Logo({ link: "https://iclient.supermap.io" })]),
            view: new ol.View({
                center: [12406035, 4304933],
                zoom: 4,
                projection: "EPSG:3857",
                multiWorld: true
            })
        });
        options = ol.source.TileSuperMapRest.optionsFromMapJSON(url, mapJSONObj);
        var layer = new ol.layer.Tile({
            source: new ol.source.TileSuperMapRest(options)
        });
        map.addLayer(layer);
        createTheme();
    });

    function createTheme() {
        var themeRangeItem1, themeRangeItem2,
            themeRangeItem3, themeRange;
        themeRangeItem1 = new ol.supermap.ThemeRangeItem({
            start: 0,
            end: 500000000000,
            style: new ol.supermap.ServerStyle({
                fillForeColor: new ol.supermap.ServerColor(211, 255, 250),
                lineColor: new ol.supermap.ServerColor(179, 209, 193),
                lineWidth: 0.1
            })
        });
        themeRangeItem2 = new ol.supermap.ThemeRangeItem({
            start: 500000000000,
            end: 1000000000000,
            style: new ol.supermap.ServerStyle({
                fillForeColor: new ol.supermap.ServerColor(178, 218, 199),
                lineColor: new ol.supermap.ServerColor(179, 209, 193),
                lineWidth: 0.1
            })
        });
        themeRangeItem3 = new ol.supermap.ThemeRangeItem({
            start: 1000000000000,
            end: 3000000000000,
            style: new ol.supermap.ServerStyle({
                fillForeColor: new ol.supermap.ServerColor(58, 178, 166),
                lineColor: new ol.supermap.ServerColor(179, 209, 193),
                lineWidth: 0.1
            })
        });
        themeRange = new ol.supermap.ThemeRange({
            rangeExpression: "SMAREA",
            rangeMode: ol.supermap.RangeMode.EQUALINTERVAL,
            items: [themeRangeItem1, themeRangeItem2, themeRangeItem3]
        });
        var themeParameters = new ol.supermap.ThemeParameters({
            datasetNames: ["Province_R"],
            dataSourceNames: ["China"],
            joinItems: null,
            themes: [themeRange]
        });

        new ol.supermap.ThemeService(url).getThemeInfo(themeParameters).then(function (serviceResult) {
            var result = serviceResult.result;
            if (result && result.newResourceID) {
                themeLayer = new ol.layer.Tile({
                    source: new ol.source.TileSuperMapRest({
                        url: url,
                        noWrap: true,
                        cacheEnabled: false,
                        transparent: true,
                        layersID: result.newResourceID,
                        transparent: true
                    })
                });
                map.addLayer(themeLayer);
            }
        });
    }
</script>
</body>
</html>